package com.szpxt.aspect;

import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Component @Aspect
public class UserAspect {

	@Around("execution(* com.szpxt.action.UserAction.*(..))")
	public void around(ProceedingJoinPoint joinPoint) throws Throwable {
		HttpServletResponse response = ServletActionContext.getResponse();
		Map<String, Object> sessionMap = ServletActionContext.getContext().getSession();
		
		Object objectPrivilege = sessionMap.get("strPrivilege");
		String strPrivilege = objectPrivilege != null ? (String)objectPrivilege : "";
		
		if(strPrivilege.indexOf("privilege_user") == -1) {
			response.setStatus(401);
			response.sendRedirect("/szpxt-beta/error/401.jsp");
		}
		else {
			joinPoint.proceed();
		}
	}
}
